﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeFile="gradesubject.aspx.cs" Inherits="admin_gradesubject" %>


<%@ Import Namespace="Infrastructure.Utility" %>
<asp:Content ContentPlaceHolderID="titleContent" runat="Server">年级-科目对应设置</asp:Content>
<asp:Content ContentPlaceHolderID="headContent" runat="Server">
    <style type="text/css">
    </style>
</asp:Content>
<asp:Content ContentPlaceHolderID="mainContent" runat="Server">
    <h4>年级-科目</h4>
    <form runat="server" class="form-horizontal">
        <div>
            <div class="pull-left" style="margin-bottom: 2px;">
                <div style="width: 450px;" class="row">
                    <div class="col-sm-5" style="padding-left: 30px;">
                        <asp:TextBox class="form-control gradecondition" Style="padding-right: 0px;" placeholder="输入年级检索." runat="server" ID="txtGrade" onkeydown="if(event.keyCode == 13) $('.searchbutton').click();" />
                    </div>
                    <div class="col-sm-7 input-group">
                        <asp:TextBox class="form-control" aria-describedby="sizing-addon1" placeholder="输入名称检索." runat="server" ID="txtName" onkeydown="if(event.keyCode == 13) $('.searchbutton').click();" />
                        <span class="input-group-addon" style="cursor: pointer;" id="sizing-addon1" onclick="$('.searchbutton').click();"><i class="cus-icon-search">&nbsp;</i></span>
                    </div>
                </div>
                <span class="hidden">
                    <asp:Button runat="server" name="btnPost" CssClass="searchbutton" OnClick="btnPost_Click" UseSubmitBehavior="false" />
                </span>
            </div>
            <div class="pull-right" style="margin-bottom: 2px;">
                <button type="button" class="btn btn-danger" onclick="if(checkSelected()) $('.deletebutton').click();"><i class="cus-icon-delete"></i>删除</button>
                <span class="hidden">
                    <asp:Button runat="server" name="btnDel" UseSubmitBehavior="false" CssClass="hidden deletebutton" OnClick="btnDel_Click" />
                </span>
            </div>
        </div>
        <input type="hidden" id="txtGoTo" name="txtGoTo" value="0" />
        <table class="table gridview">
            <tr>
                <th>
                    <input type="checkbox" onchange="$(this).parentsUntil('table').find('.selector').attr('checked',this.checked);" />
                    选择
                </th>
                <th>年级</th>
                <th>科目</th>
                <th>操作</th>
            </tr>
            <asp:Repeater ID="lstGradeSubject" runat="server">
                <ItemTemplate>
                    <tr>
                        <td>
                            <input type="checkbox" class="selector" name="selector" value="<%# Eval("gsid") %>" />
                            <input type="hidden" />
                        </td>
                        <td><%#Eval("gname") %></td>
                        <td><%#Eval("sname") %></td>
                        <td><a href="chapter.aspx?sid=<%# Eval("sid") %>&gsid=<%# Eval("gsid") %>" target="_top">章节</a></td>
                    </tr>
                </ItemTemplate>
            </asp:Repeater>
        </table>
        <div>
            <div class="btn-group pull-left" role="group">
                <button type="button" class="btn btn-default" onclick="$('#txtGoTo').val('1');$('.gotoindex').click();">1</button>
                <button type="button" class="btn btn-default" onclick="$('#txtGoTo').val('<%=Index-1 %>');$('.gotoindex').click();"><<</button>
                <button type="button" class="btn btn-default" onclick="$('#txtGoTo').val('<%=Index+1 %>');$('.gotoindex').click();">>></button>
                <button type="button" class="btn btn-default" onclick="$('#txtGoTo').val('<%=TotalSize %>');$('.gotoindex').click();"><%=TotalSize %></button>
                <input type="text" class="form-control" style="width: 20px; margin-left: 2px;" placeholder="Go" onkeydown="if(event.keyCode==13) { $('#txtGoTo').val(this.value);$('.gotoindex').click();}" />
                <asp:Button runat="server" CssClass="hidden gotoindex" UseSubmitBehavior="false" OnClick="btnNavigate_Click" />
            </div>
            <div class="pull-right">
                <%=Index %>/<%=TotalSize %>页
            </div>
        </div>
        <div class="clearfix"></div>
        <br />
        <h4>年级-科目对应</h4>
        <hr style="margin-bottom: 5px;" />
        <div class="row" style="padding-left: 15px;">
            <div class="col-sm-10">
                <label for="ngrade">对应：</label>
                <input type="text" name="ngrade" id="ngrade" placeholder="请输入并选择年级" class="form-control" style="width: 45%; display: inline;" data-autocomplete-options='{data: "grade.aspx?data=list",text_field:"name",value_field:"nid"}' onchange="autoCompleteData(this,'#ngradeId');" />
                <input type="hidden" id="ngradeId" />
                <input type="text" id="nsubject" name="nsubject" class="form-control" placeholder="请输入并选择科目." style="width: 45%; display: inline;" data-autocomplete-options='{data: "subject.aspx?data=list",text_field:"name",value_field:"sid"}' onchange="autoCompleteData(this,'#nsubjectId');" />
                <input type="hidden" id="nsubjectId" />
            </div>
            <div class="co-sm-2 text-right">
                <a class="btn btn-success" href="javascript:void(0)" onclick="doMapGradeSubject();"><i class="cus-icon-add"></i>确定</a>
            </div>
        </div>
    </form>
</asp:Content>
<asp:Content ContentPlaceHolderID="scriptContent" runat="Server">
    <script type="text/javascript">
        //验证点击删除时，是否勾选了项目。
        function checkSelected() {
            var hasSel = false;
            $(".selector").each(function (index, e) {
                if (this.checked) return hasSel = true;
            });

            if (!hasSel) {
                alert("请勾选需要删除的项目！");
                return false;
            }
            return true;
        }
        $(document).ready(function () {
            activeAutoComplete($(".gradecondition")[0]);
            activeAutoComplete($("#ngrade")[0]);
            activeAutoComplete($("#nsubject")[0]);
        });

        function autoCompleteData(sender, selector) {
            if (!sender.value || !$.trim(sender.value) || $.trim(sender.value) == $(sender).attr("placeholder")) return;
            $(selector).val($(sender).data("real-value") || "");//$("input[name*='']")
        }

        var doMapGradeSubject = function () {
            var data = {
                gid: $("#ngradeId").val() || "0",
                sid: $("#nsubjectId").val() || "0"
            };

            if (data.gid == "0") return alert("请选择年级.");
            if (data.sid == "0") return alert("请选择科目.");

            request("gradesubject.aspx?do=save", data, function () {
                $('#txtGoTo').val('<%=TotalSize %>');
                $('.gotoindex').click();
            });
        };
    </script>
</asp:Content>
